package com.example.composetutorial


import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.CompositingStrategy
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.drawscope.clipPath
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp


class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
            /*AlertDialogExample(
                { Unit },
                { Unit },
                "dialogTitle",
                "dialogText"
            )*/

            /*Example({ Unit })*/
            /*ClickCounter()*/
           /*ArtistCardColumn()*/

/*val artist=Artist()
            ArtistCardRow(artist)*/
            /*ArtistAvatar()*/
            /*flashLight()*/

Avatar()
        }
    }
}





/*@Preview
@Composable
fun PreviewExample() {

    Example({ Unit })
}*/

/*var clicks: Int = 0
fun Click() {
    clicks++
    println("I've been clicked $clicks times")

}*/

@Composable
fun ClickCounter(  ) {
    var  clicks by remember {
        mutableStateOf(0)
    }

    println("ClickCounterI've been clicked $clicks times")

    Button(onClick = { clicks++ }) {
        Text("I've been clicked $clicks times")
    }
}

fun Click_1(value: String) {
    println("hello wo")

}
/*@Composable
fun ClickCounter(clicks: Int, onClick: (clicks) -> Unit) {
    Button(onClick = {()->clicks++  }) {
        Text("I've been clicked $clicks times")
    }
}*/
/*@Composable
fun ArtistCardColumn() {
    Column {
        Text("Alfred Sisley")
        Text("3 minutes ago")
    }
}*/
fun animateContentSize_1(init :Int, fin :Int) {
    println("hello wo")

}
/*@Composable
fun ArtistCardRow(artist: Artist) {
    Image(
            painter = painterResource(R.drawable.profile_picture),
            contentDescription = null,
            modifier = Modifier
                .size(300.dp)
                .clickable(onClick = { Unit })
                .paint(painterResource(R.drawable.bingwallpaper))
                *//*.draggable(
                    DraggableState { }, Orientation.Horizontal, enabled = true
                )*//*
                .shadow(100.dp, CircleShape, true, Color.Black, Color.Red)//animateContentSize (finishedListtener={animateContentSize_1(300.dp,0.dp )}   )

        )
    val brush:Brush=linearGradient(listOf(Color.Red, Color.Blue))


    Button(onClick = { Unit },
        Modifier.size(100.dp).background(brush, CircleShape,0.1F).blur(3.dp).padding(20.dp).clip(CircleShape).paint(painterResource(R.drawable.profile_picture)).border(
            BorderStroke(3.dp,Color.Blue)
        )) {

    }
    Row(Modifier.border(BorderStroke(3.dp,Color.Blue))) {
    Text(
        "text"

    )
}
}*/
/*@Composable
fun ArtistAvatar() {
    Box {
        Image(
            painter = painterResource(R.drawable.profile_picture),
            contentDescription = "profile_picture",
            //modifier = Modifier.size(120.dp).aspectRatio(2f)
                    modifier = Modifier.aspectRatio(2f)

                .clip(CircleShape)
                .border(1.5.dp, MaterialTheme.colorScheme.secondary,CircleShape )
        )
        Icon(Icons.TwoTone.CheckCircle, contentDescription = "Check mark",Modifier.absoluteOffset(90.dp,90.dp).border(2.dp,MaterialTheme.colorScheme.secondary,CircleShape))
    }
}*/
@Composable
fun Avatar() {
    Image(painter = painterResource(id = R.drawable.profile_picture),
        contentDescription = "Dog",
        contentScale = ContentScale.Crop,
        modifier = Modifier
            .size(120.dp)
            .aspectRatio(1f)
            .background(
                Brush.linearGradient(
                    listOf(
                        Color(0xFFC5E1A5),
                        Color(0xFF80DEEA)
                    )
                )
            )
            .padding(8.dp)


            //.fancy(1.0f)


            .graphicsLayer {
                println(size.width)
                /*scaleX=0.5f
                scaleY=0.5f

                shape = CircleShape*/
                compositingStrategy = CompositingStrategy.Offscreen
            }
            .drawWithCache {
                val path = Path()
                println(size.width)
                path.addOval(
                    Rect(
                        topLeft = Offset.Zero,
                        bottomRight = Offset(size.width, size.height)

                    )
                )
                onDrawWithContent {
                    println(size.width)
                    clipPath(path) {
                        println(size.width)
                        // this draws the actual image - if you don't call drawContent, it wont
                        // render anything
                        this@onDrawWithContent.drawContent()
                    }
                    val dotSize = size.width / 8f
                    // Clip a white border for the content

                    drawCircle(

                        Color.Green,
                        radius = dotSize,
                        center = Offset(
                            x = size.width - dotSize,
                            y = size.height - dotSize
                        ),
                        blendMode = BlendMode.Clear
                    )


                    // draw the red circle indication
                    drawCircle(

                        Color(Color.Blue.value), radius = dotSize * 0.8f,
                        // Color(0xFFEF5350), radius = dotSize * 0.8f,
                        center = Offset(
                            x = size.width - dotSize,
                            y = size.height - dotSize
                        )
                    )
                }
            }

    )

}
/*@Composable
fun ArtistAvatar_12_1() {
Canvas(Modifier.size(120.dp)) {
    println("size.width")
    println(size.width)

    drawRect(color = Color.Gray) // Draw grey background
    // Inset content by 10 pixels on the left/right sides and 12 by the
    // top/bottom
    inset(120.0f, 120.0f) {
        println(size.width)
        val quadrantSize = size / 2.0f

        // Draw a rectangle within the inset bounds
        drawRect(
            size = quadrantSize,
            color = Color.Red
        )

        rotate(45.0f) {
            drawRect(size = quadrantSize, color = Color.Blue)
        }
        drawCircle(Color.Yellow)
    }
}
}*/
@Composable
fun toggleLinearGradient() {
    /*Box(
        Modifier.drawWithCache {
            val gradient = Brush.linearGradient(
                colors = listOf(Color.Red, Color.Blue),
                start = Offset.Zero,
                end = Offset(size.width, size.height)
            )
            onDrawBehind {
                drawRect(gradient)
            }
        }
    )*/
    val colors1 = listOf(Color.Red, Color.Blue)
    val colors2 = listOf(Color.Yellow, Color.Green)
    var toggle by remember { mutableStateOf(true) }
    Box(
        Modifier
            .size(120.dp)
            .background(Color.Red)
            .clickable { toggle = !toggle }
            .drawWithCache {
                val gradient = Brush.linearGradient(
                    colors = if (toggle) colors1 else colors2,
                    start = Offset.Zero,
                    end = Offset(size.width, size.height)
                )
                onDrawBehind {
                    drawRect(gradient)
                }
            }
    )

}
@Composable
fun flashLight() {
    var pointerOffset by remember {
        mutableStateOf(Offset(0f, 0f))
    }
    Column(
        modifier = Modifier
            .fillMaxSize()
            .pointerInput("dragging") {
                detectDragGestures { change, dragAmount ->
                    pointerOffset += dragAmount
                }
            }
            .onSizeChanged {
                pointerOffset = Offset(it.width / 2f, it.height / 2f)
            }
            .drawWithContent {
                drawContent()
                // draws a fully black area with a small keyhole at pointerOffset that’ll show part of the UI.
                drawRect(
                    Brush.radialGradient(
                        listOf(Color.Transparent, Color.Black),
                        center = pointerOffset,
                        radius = 100.dp.toPx(),
                    )
                )
            }
    ) {
        // Your composables here
    }

}
@Composable
fun OutlinedTextField(value: String,onValueChange: (String)->Unit) {

}
@Composable
fun scaffold() {

}
